const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

function encryptIdNo(str) {
  if (null != str && str != undefined) {
    var pat = /(\d{4})\d*(\d{4})/;
    return str.replace(pat, '$1***********$2');
  } else {
    return "";
  }
}
function pad(timeEl, total = 2, str = '0') {
  return timeEl.toString().padStart(total, str)
}

function parseTime(str) {
  let d = str.substring(0, 10)
  let t = str.substring(11, 19)
  return d + ' ' + t
}

module.exports = {
  formatTime,
  encryptIdNo,
  pad,
  parseTime
}

